package com.lanchetech.user.controller;

import com.lanchetech.bean.request.CardConsumptionFundItemReq;
import com.lanchetech.bean.request.TenantPageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.CardConsumptionFundItemVo;
import com.lanchetech.bean.vo.CardConsumptionUserVo;
import com.lanchetech.bean.vo.ShopVO;
import com.lanchetech.bean.vo.StoreDetailVO;
import com.lanchetech.common.enums.AccessType;
import com.lanchetech.entity.Category;
import com.lanchetech.entity.Tenant;
import com.lanchetech.entity.User;
import com.lanchetech.service.CardConsumptionFundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/card/consumption")
@Api(value = "消费金", tags = "消费金")
public class MiniCardConsumptionController {

    @Autowired
    private CardConsumptionFundService cardConsumptionFundService;

    @GetMapping("/get")
    @ApiOperation("获取我的消费金")
    public ResultData<CardConsumptionUserVo> get(@AuthenticationPrincipal User user) {
        ResultData<CardConsumptionUserVo> cardConsumptionUser = cardConsumptionFundService.get(user);
        return cardConsumptionUser;
    }

    @GetMapping("/get/spu")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "总页数不传,默认1页", defaultValue = "1", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数不传,默认10条", defaultValue = "10", paramType = "query", dataType = "Integer"),
    })
    @ApiOperation("获取消费金商品")
    public ResultData<BasePageResp<CardConsumptionFundItemVo>> getConsumptionSpu(@AuthenticationPrincipal User user,
                                                                                 @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                 @RequestParam(value = "priceSort", required = false) Integer priceSort,
                                                                                 @RequestParam(value = "salesSort", required = false) Integer salesSort,
                                                                                 @RequestParam(value = "rid", required = false) Integer rid) {
        CardConsumptionFundItemReq req = new CardConsumptionFundItemReq();
        req.setPageNo(pageNo);
        req.setPageSize(pageSize);
        req.setUserId(user.getId());
        req.setAccessType(AccessType.MINI);
        req.setStatus((byte) 1);
        req.setPriceSort(priceSort);
        req.setSalesSort(salesSort);
        req.setRid(rid);
        return cardConsumptionFundService.getBindSpu(req);
    }

    @GetMapping("/get/store")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "总页数不传,默认1页", defaultValue = "1", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数不传,默认10条", defaultValue = "10", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "cardConsumptionFundId", value = "消费金ID", paramType = "query", dataType = "Long"),
    })
    @ApiOperation("获取消费金商家")
    public ResultData<BasePageResp<StoreDetailVO>> getCardStore(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                @RequestParam(value = "cardConsumptionFundId") Long cardConsumptionFundId) {
        TenantPageReq tenantPageReq = new TenantPageReq();
        tenantPageReq.setPageNo(pageNo);
        tenantPageReq.setPageSize(pageSize);
        tenantPageReq.setCardConsumptionFundId(cardConsumptionFundId);
        return cardConsumptionFundService.getCardStore(tenantPageReq);
    }

    @GetMapping("/get/storeSpu")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "总页数不传,默认1页", defaultValue = "1", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数不传,默认10条", defaultValue = "10", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "storeId", value = "商户ID", paramType = "query", dataType = "Long"),
    })
    @ApiOperation("获取商家消费金商品")
    public ResultData<BasePageResp<CardConsumptionFundItemVo>> getStoreSpu(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                           @RequestParam(value = "storeId") Long storeId) {
        CardConsumptionFundItemReq req = new CardConsumptionFundItemReq();
        req.setPageNo(pageNo);
        req.setPageSize(pageSize);
        req.setStatus((byte) 1);
        req.setStoreId(storeId);
        return cardConsumptionFundService.getStoreSpu(req);
    }


}
